package com.frinder.robot.log;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.sift.AbstractDiscriminator;
import com.google.common.base.Strings;

/**
 * @ClassName SplitRobotFileDiscriminator
 * @Description //TODO
 * @Author frinder
 * @Date 2019/1/10 15:24
 * @Version 1.0
 */
public class SplitRobotFileDiscriminator extends AbstractDiscriminator<ILoggingEvent> {

    public static final String KEY = "robot";

    public static final String ROBOT_KEY = "ROBOT";

    @Override
    public String getDiscriminatingValue(ILoggingEvent iLoggingEvent) {
        String robotName = iLoggingEvent.getMDCPropertyMap().get(ROBOT_KEY);
        if (Strings.isNullOrEmpty(robotName)) {
            return "NA";
        }
        return robotName;
    }

    @Override
    public String getKey() {
        return KEY;
    }

}
